const MovieLevels = [{
  id: 1,
  name: '经典本',
  version: 1,
  price: 2380,
  openPrice: 3600,
  todayPrice: 5600,
  returnMoneySupport: 0,
  enableHolidayPrice: 1
}, {
  id: 2,
  name: 'VIP本',
  version: 1,
  price: 4660,
  openPrice: 9600,
  todayPrice: 9600,
  returnMoneySupport: 1,
  enableHolidayPrice: 0
}, {
  id: 3,
  name: '飙升本',
  version: 1,
  price: 7250,
  openPrice: 30600,
  todayPrice: 30600
}]

function add(level) {
  const r = JSON.parse(JSON.stringify(level))
  r.id = MovieLevels[MovieLevels.length - 1].id + 1
  r.todayPrice = r.openPrice
  MovieLevels.push(r)
}

function list(name) {
  const mocks = MovieLevels.filter(item => {
    return !(name && (!item.name || item.name.indexOf(name) === -1))
  })
  return { success: true, data: mocks }
}

function find(id) {
  id = id ? parseInt(id) : null
  for (let i = 0; i < MovieLevels.length; ++i) {
    if (MovieLevels[i].id === id) {
      return MovieLevels[i]
    }
  }
  return null
}

module.exports = { list, add, find, MovieLevels }
